package com.chanyachting.emall.domain;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;

import com.chanyachting.emall.dao.OpertionmenuDAO;
import com.chanyachting.emall.domain.base.BaseOpertionmenu;

/**
 * This is the object class that relates to the opertionmenu table.
 * Any customizations belong here.
 */
public class Opertionmenu extends BaseOpertionmenu {

/*[CONSTRUCTOR MARKER BEGIN]*/
	public Opertionmenu () {
		super();
	}

	/**
	 * Constructor for primary key
	 */
	public Opertionmenu (java.lang.Integer _id) {
		super(_id);
		
		Opertionmenu menu=(Opertionmenu)new OpertionmenuDAO().load(Opertionmenu.class, _id);
		
		if(menu!=null){
			
			try {
				BeanUtils.copyProperties(this, menu);
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	/**
	 * Constructor for required fields
	 */
	public Opertionmenu (
		java.lang.Integer _id,
		java.lang.String _url,
		java.lang.String _name) {

		super (
			_id,
			_url,
			_name);
	}
/*[CONSTRUCTOR MARKER END]*/
	
	
	
	public static List<Opertionmenu> list(){
		
		return new OpertionmenuDAO().find("from Opertionmenu");	
	}
	
	
	public static List<Opertionmenu> listByGorupId(int groupId){
		
		String args[]={String.valueOf(groupId)};
		
		return new OpertionmenuDAO().find("from Opertionmenu where groupId=?",args);	
	}
	
	
	
	public static List<Opertionmenu> listByIdList(List<String> idList){
		
		if(idList==null || idList.size()<1) return null;
		
		String tag="";
		
		for(int i=0;i<idList.size();i++){
			
			tag+=String.valueOf(idList.get(i))+",";
		}
		
		tag=tag.substring(0,tag.length()-1);
		
		return new OpertionmenuDAO().find("from Opertionmenu where id in("+tag+")");	
	}

	@Override
	public boolean equals(Object obj) {
		
		if(obj==null) return false;
		
		Opertionmenu om=(Opertionmenu)obj;
	
		if(this.getId()==om.getId()) return true;
		
		return false;
	}
	
	
	
	public boolean save(){
		
		new OpertionmenuDAO().save(this);
		
		return true;
	}
	
	public boolean update(){
		
		new OpertionmenuDAO().update(this);
		
		return true;
	}
	
	public boolean delete(){
		
		new OpertionmenuDAO().delete(this);
		
		return true;
	}
	
	
}